<template>
  <div>
    <el-result icon="success" title="支付成功" :subTitle="sum + ' 秒后返回'">
      <template slot="extra">
        <el-button type="primary" size="medium" @click="fanhui">返回</el-button>
      </template>
    </el-result>
  </div>
</template>

<script>
export default {
  data() {
    return {
      time: null,
      sum: 10,
    };
  },
  mounted() {
    this.time = setInterval(() => {
      this.sum--;
      if (this.sum <= 0) {
        clearInterval(this.time);
        this.$router.push({ name: "user-order-all" });
      }
    }, 1000);
    const { out_trade_no, id } = this.$route.query;
    let outtrade = out_trade_no

      .match(/_(\d+)_/)
      .at(0)
      .replaceAll("_", "");
    if (outtrade) {
      this.$request.put("order/update", {
        id: Number(outtrade),
        paymentStatus: 4,
      });
    } else {
      this.$request.put("order/update", {
        id: id,
        paymentStatus: 4,
      });
    }
  },
  methods: {
    fanhui() {
      this.time && clearInterval(this.time);
      this.$router.push({ name: "user-order-all" });
    },
  },
};
</script>

<style></style>
